package com.bz.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bz.common.PageInfo;
import com.bz.common.UserConfig;
import com.bz.dao.BannerDao;
import com.bz.entity.BannerEntity;
import com.bz.entity.UserEntity;
import com.bz.service.IBannerService;

@Service
public class BannerServiceImpl implements IBannerService {

    @Autowired
    private BannerDao bannerDao;

    @Override
    public PageInfo<BannerEntity> list(PageInfo page, LambdaQueryWrapper<BannerEntity> queryWrapper) {
        queryWrapper.orderByDesc(BannerEntity::getUpdateDate);
        return bannerDao.selectPage(page, queryWrapper);
    }

    @Override
    public void add(BannerEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setCreateBy(lu.getUsername());
        data.setCreateDate(new Date());
        data.setUpdateBy(lu.getUsername());
        bannerDao.insert(data);
    }

    @Override
    public void update(BannerEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setUpdateBy(lu.getUsername());
        bannerDao.updateById(data);
    }

    @Override
    public void delete(Long id) {
        bannerDao.deleteById(id);
    }

}
